<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="shortcut icon" href="/favicon.ico"/>
  <link rel="bookmark" href="/favicon.ico"/>
  <title>CloudEI 登录</title>
  <!-- Theme color -->
  <meta name="theme-color" content="#3c8dbc">
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">

  
  <link rel="stylesheet" href="amis/antd.css" />
  <link rel="stylesheet" href="amis/helper.css" />

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

</head>
<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    <span>Cloud<b>EI</b></span>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body" style="padding-top: 2.3rem; padding-bottom: 3rem;">
    <div id="msg" style="text-align: center; color: red; padding-bottom: 1rem;">
      
    </div>
    <form action="#" method="post">
      <div class="form-group has-feedback">
        <input id="username" class="form-control" placeholder="用户名" value="admin">
        <span class="fa fa-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input id="password" type="password" class="form-control" placeholder="密码" value="123">
        <span class="fa fa-key form-control-feedback"></span>
      </div>
      <div class="row">
        <!-- /.col -->
        <div class="col-xs-12">
          <button type="button" id="submit" class="btn btn-primary btn-block btn-flat" style="margin-top: 1rem;">登 录</button>
        </div>
        <!-- /.col -->
      </div>
    </form>

  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- MD5 -->
<script src="js/md5.js"></script>
<script type="module">
  import request from "./js/request.js"
  $(function () {
    $("#submit").click(function(){
      let username=$("#username").val();
      let password=$("#password").val();
      if(!username){
        $("#msg").text("请输入正确的用户名");
      }
      else if(!password){
        $("#msg").text("请输入正确的密码");
      }
      else{
        $("#msg").text("");
        if(password.length<32){
          password=$.md5(password);
        }
        request("login/in",{username:username,password:password},function(data){
          if(!data.success){
            $("#msg").text(data.msg);
          }
          else{
            let pid=query("pid");
            window.location="index.html"+(pid?("?pid="+pid):"");
          }
        });
      }
      return false;
    });

    function query(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }

    $("#username").keydown(function (e) {
      var curKey = e.which;
      if (curKey == 13) {
        if(!$("#username").val()){
          $("#msg").text("请输入正确的用户名");
          return false;
        }
        else{          
          $("#msg").text("");
          $("#password").focus();
          return false;
        }
      }
    });
    $("#password").keydown(function (e) {
      var curKey = e.which;
      if (curKey == 13) {
        $("#submit").click();
        return false;
      }
    });
  });
</script>
</body>
</html>
